package com.gwcloud.coffeeman.common.comunication.invoker;

import com.gwcloud.coffeeman.common.comunication.Annotation.InvokerParam;
import com.gwcloud.coffeeman.common.comunication.invokerparam.ExampleInvokerParams;
import com.gwcloud.coffeeman.common.comunication.invokerparam.InvokerParams;
import com.gwcloud.coffeeman.common.utils.ApplicationContextUtil;
import com.gwcloud.coffeeman.common.utils.LogWriter;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryUtils;

import javax.xml.ws.spi.Invoker;

/**
 * @date: 2020/10/15
 * @author: ganwei
 * @Desc: 程序描述
 */
public abstract class AbstractInvoker {
    private String invoker;
    public AbstractInvoker(String transcode, String version) {
        LogWriter.trace(getClass(),"transcode-{}, version-{}", transcode, version);

        //此处要根据子类标签构造参数
        InvokerParams param = null;
        try{
            InvokerParam invokerParam = getClass().getAnnotation(InvokerParam.class);
            String paramClassStr = invokerParam.value();
            System.out.println(paramClassStr);
            Object paramo = ApplicationContextUtil.getBean(paramClassStr);
            if(InvokerParams.class.isAssignableFrom(paramo.getClass())){
                param = (InvokerParams) paramo;
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        //调用勾子
        if(param != null) {
            init(param);
        }else{
            init();
        }

    }


    public void invoke(){
        System.out.println("pre invoke");

        System.out.println("do invoke");

        System.out.println("pre invoke");
    }
    protected void init(InvokerParams params){

    }

    //先啥都不做，可实现些公共的默认逻辑
    protected void init(){

    }
}
